package com.ssh.controller;

import com.ssh.domain.User;
import com.ssh.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
public class UserCtrl {
    @Resource
    private  UserService userService;
    @RequestMapping("/addUser")
    public String addUser(User user){
        System.out.println("新增用户："+user.getName()+", "+user.getAge());
        userService.addUser(user);
        return "index";
    }
    @RequestMapping(value = "/getUser",method = RequestMethod.GET)
    @ResponseBody
    public List<User> getUser(HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");
        List<User> list=userService.getUsers();
        System.out.println(list);
        return list;
    }

}
